home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12244 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  37 lines

  1. Newsgroups: comp.lang.c,comp.os.ms-windows.programmer.win32
  2. Path: news.inap.net!news1!ind-009-237-98
  3. From: dlmiller@iquest.net (Doug Miller)
  4. Subject: Re: How can I check whether I file exists in a multi-user environment?
  5. X-Nntp-Posting-Host: ind-009-237-98.iquest.net
  6. Message-ID: <Dp1oM8.Cns@iquest.net>
  7. Sender: news@iquest.net (News Admin)
  8. Organization: IQuest Network Services
  9. X-Newsreader: News Xpress Version 1.0 Beta #2.1
  10. References: <4jh4tl$t4c_002@chem.uva.nl>
  11. Date: Fri, 29 Mar 1996 19:56:33 GMT
  12.  
  13. brands@chemeng.chem.uva.nl (Danny Brands) wrote:
  14. >Hi all,
  15. >
  16. >I need to check whether a file exists on a hard drive. Because I'm in a
  17. >multi-user environment I can't simply open the file. Is there another way?
  18. >
  19. >I'm using MSVC++ 2.0 / Win95.
  20. >
  21. >I'm looking in the Win32 API help file, but I can't really figure out how to
  22. >do it. In VB you can use the dir() command.
  23. >
  24. >Anyway, thanks in advance!
  25. >
  26. >Regards,
  27. >
  28. >Danny
  29. >
  30.         * * * * C A U T I O N * * * *
  31. Although this will work in many implementations, to the best of my knowledge it is *NOT* ANSI C.
  32.  
  33. #include <io.h>
  34. int file_exists (char *filename) {
  35.     return (access(filename, 0) == 0);
  36. } /* returns -1 if file exists, 0 if it does not */
  37.